home *** CD-ROM | disk | FTP | other *** search
- head 1.5;
- branch ;
- access ;
- symbols ;
- locks hyc:1.5; strict;
- comment @ * @;
-
-
- 1.5
- date 88.06.01.19.26.31; author hyc; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 88.06.01.15.32.51; author hyc; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 88.06.01.15.27.38; author hyc; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.04.11.17.59.09; author hyc; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.04.11.17.56.12; author hyc; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.5
- log
- @Changed compilation conditionals
- @
- text
- @/*
- * $Header: arcext.c,v 1.4 88/06/01 15:32:51 hyc Locked $
- */
-
- /*
- * ARC - Archive utility - ARCEXT
- *
- * Version 2.19, created on 10/24/86 at 14:53:32
- *
- * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
- *
- * By: Thom Henderson
- *
- * Description: This file contains the routines used to extract files from an
- * archive.
- *
- * Language: Computer Innovations Optimizing C86
- */
- #include <stdio.h>
- #include "arc.h"
- #if !MSDOS
- #include <ctype.h>
- #endif
-
- void openarc(), closearc(), setstamp();
- int free(), match(), readhr(), unpack();
- char *strcpy(), *strcat();
-
- void
- extarc(num, arg, prt) /* extract files from archive */
- int num; /* number of arguments */
- char *arg[]; /* pointers to arguments */
- int prt; /* true if printing */
- {
- struct heads hdr; /* file header */
- int save; /* true to save current file */
- int did[MAXARG];/* true when argument was used */
- char *i, *rindex(); /* string index */
- char **name, *malloc(); /* name pointer list,
- * allocator */
- int n; /* index */
- void extfile();
-
- name = (char **) malloc(num * sizeof(char *)); /* get storage for name
- * pointers */
-
- for (n = 0; n < num; n++) { /* for each argument */
- did[n] = 0; /* reset usage flag */
- #if !MTS
- if (!(i = rindex(arg[n], '\\'))) /* find start of name */
- if (!(i = rindex(arg[n], '/')))
- if (!(i = rindex(arg[n], ':')))
- i = arg[n] - 1;
- #else
- if (!(i = rindex(arg[n], sepchr[0])))
- if (arg[n][0] != tmpchr[0])
- i = arg[n] - 1;
- else
- i = arg[n];
- #endif
- name[n] = i + 1;
- }
-
-
- openarc(0); /* open archive for reading */
-
- if (num) { /* if files were named */
- while (readhdr(&hdr, arc)) { /* while more files to check */
- save = 0; /* reset save flag */
- for (n = 0; n < num; n++) { /* for each template
- * given */
- if (match(hdr.name, name[n])) {
- save = 1; /* turn on save flag */
- did[n] = 1; /* turn on usage flag */
- break; /* stop looking */
- }
- }
-
- if (save) /* extract if desired, else skip */
- extfile(&hdr, arg[n], prt);
- else
- fseek(arc, hdr.size, 1);
- }
- } else
- while (readhdr(&hdr, arc)) /* else extract all files */
- extfile(&hdr, "", prt);
-
- closearc(0); /* close archive after reading */
-
- if (note) {
- for (n = 0; n < num; n++) { /* report unused args */
- if (!did[n]) {
- printf("File not found: %s\n", arg[n]);
- nerrs++;
- }
- }
- }
- free(name);
- }
-
- void
- extfile(hdr, path, prt) /* extract a file */
- struct heads *hdr; /* pointer to header data */
- char *path; /* pointer to path name */
- int prt; /* true if printing */
- {
- FILE *f, *fopen(); /* extracted file, opener */
- char buf[STRLEN]; /* input buffer */
- char fix[STRLEN]; /* fixed name buffer */
- char *i, *rindex(); /* string index */
-
- if (prt) { /* printing is much easier */
- unpack(arc, stdout, hdr); /* unpack file from archive */
- printf("\f"); /* eject the form */
- return; /* see? I told you! */
- }
- strcpy(fix, path); /* note path name template */
- #if !MTS
- if (*path) {
- if (!(i = rindex(fix, '\\'))) /* find start of name */
- if (!(i = rindex(fix, '/')))
- if (!(i = rindex(fix, ':')))
- i = fix - 1;
- } else i = fix -1;
- #else
- if (!(i = rindex(fix, sepchr[0])))
- if (fix[0] != tmpchr[0])
- i = fix - 1;
- else
- i = fix;
- #endif
- strcpy(i + 1, hdr->name); /* replace template with name */
-
- if (note)
- printf("Extracting file: %s\n", fix);
-
- if (warn && !overlay) {
- if (f = fopen(fix, "r")) { /* see if it exists */
- fclose(f);
- printf("WARNING: File %s already exists!", fix);
- fflush(stdout);
- while (1) {
- printf(" Overwrite it (y/n)? ");
- fflush(stdout);
- fgets(buf, STRLEN, stdin);
- *buf = toupper(*buf);
- if (*buf == 'Y' || *buf == 'N')
- break;
- }
- if (*buf == 'N') {
- printf("%s not extracted.\n", fix);
- fseek(arc, hdr->size, 1);
- return;
- }
- }
- }
- #if !MTS
- if (!(f = fopen(fix, "wb")))
- #else
- {
- fortran create();
- void memset();
- char c_name[256];
- struct crsize {
- short maxsize, cursize;
- } c_size;
- char c_vol[6];
- int c_type;
- strcpy(c_name, fix);
- strcat(c_name, " ");
- c_size.maxsize = 0;
- c_size.cursize = hdr->length / 4096 + 1;
- memset(c_vol, 0, sizeof(c_vol));
- c_type = 0x100;
- create(c_name, &c_size, c_vol, &c_type);
- }
- if (image) {
- f = fopen(fix, "wb");
- } else
- f = fopen(fix, "w");
- if (!f)
- #endif
- {
- if (warn) {
- printf("Cannot create %s\n", fix);
- nerrs++;
- }
- fseek(arc, hdr->size, 1);
- return;
- }
- /* now unpack the file */
-
- unpack(arc, f, hdr); /* unpack file from archive */
- #if MSDOS
- setstamp(f, hdr->date, hdr->time); /* set the proper date/time
- * stamp */
- #endif
- fclose(f); /* all done writing to file */
- #if UNIX || GEMDOS
- setstamp(fix, hdr->date, hdr->time); /* use filename for stamp */
- #endif
- }
- @
-
-
- 1.4
- log
- @Merged Atari ST code
- @
- text
- @d2 1
- a2 1
- * $Header: arcext.c,v 1.3 88/06/01 15:27:38 hyc Locked $
- d21 1
- a21 1
- #ifndef MSDOS
- d49 1
- a49 1
- #ifndef MTS
- d118 1
- a118 1
- #ifndef MTS
- d157 1
- a157 4
- #ifdef BSD
- if (!(f = fopen(fix, "w")))
- #endif
- #ifdef DOS
- d159 1
- a159 2
- #endif
- #ifdef MTS
- d194 1
- a194 1
- #ifdef MSDOS
- d199 2
- a200 5
- #ifdef BSD
- setstamp(fix, hdr->date, hdr->time); /* use filename for BSD stamp */
- #endif
- #ifdef GEMDOS
- setstamp(fix, hdr->date, hdr->time); /* FIX ME */
- @
-
-
- 1.3
- log
- @Fix declarations
- @
- text
- @d2 1
- a2 1
- * $Header: arcext.c,v 1.4 88/04/19 01:39:42 hyc Exp $
- d119 1
- d124 1
- d157 7
- a163 3
- #ifndef MTS
- if (!(f = fopen(fix, "w"))) {
- #else
- d185 1
- a185 1
- if (!f) {
- d187 1
- d205 3
- @
-
-
- 1.2
- log
- @re-synch with MTS, formatting
- @
- text
- @d2 1
- a2 11
- * $Log: arcext.c,v $
- * Revision 1.1 88/04/11 17:56:12 hyc
- * Initial revision
- *
- * Revision 1.4 87/08/13 17:03:21 hyc
- * Run thru the indent program...
- * Revision 1.3 87/07/21 11:39:59 hyc minor
- * fixups
- *
- * Revision 1.2 87/07/21 07:32:17 hyc added BSD goodies
- *
- d21 3
- d25 5
- a29 1
- INT
- d31 1
- a31 1
- INT num; /* number of arguments */
- d33 1
- a33 1
- INT prt; /* true if printing */
- d36 2
- a37 2
- INT save; /* true to save current file */
- INT did[25];/* true when argument was used */
- d41 2
- a42 2
- INT n; /* index */
- INT extfile();
- d101 1
- a101 1
- INT
- d105 1
- a105 1
- INT prt; /* true if printing */
- d108 2
- a109 2
- char buf[100]; /* input buffer */
- char fix[100]; /* fixed name buffer */
- a136 3
- #ifdef MTS
- if ((buf[0] = fgetc(f)) != EOF) { /* kludge for temp files */
- #endif
- d143 1
- a143 1
- fgets(buf, 100, stdin);
- a152 3
- #ifdef MTS
- }
- #endif
- d160 1
- a176 1
- fseek(f, 0, 0);
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d2 4
- a5 1
- * $Log: arcext.c,v $
- d42 1
- a42 1
- char **name, *malloc(); /* name pointer list, *
- d47 2
- a48 2
- name = (char **) malloc(num * sizeof(char *));
- /* get storage for name * pointers */
- d73 1
- a73 1
- for (n = 0; n < num; n++) { /* for each template *
- d104 1
- a104 1
- static INT
- d201 2
- a202 2
- setstamp(f, hdr->date, hdr->time);
- /* set the proper date/time * stamp */
- d206 1
- a206 2
- setstamp(fix, hdr->date, hdr->time);
- /* use filename for BSD stamp */
- @
-